#ifndef CALENDAR_H
#define CALENDAR_H

#include<QWidget>
#include<QVector>
#include<QDate>
#include<QTextCharFormat>
#include<fstream>

class QTableWidget;
class QTableWidgetItem;
class QCalendarWidget;
class QLabel;
class QTimeEdit;
class QComboBox;
class QTextEdit;
class QLineEdit;
class QDateTimeEdit;

struct Events
{
	QTableWidgetItem *title;
	QTableWidgetItem *location;
	QTableWidgetItem *description;
	QDateTimeEdit *begin;
	QDateTimeEdit *end;
	QComboBox *recurrence;
};

class Calendar : public QWidget
{
	Q_OBJECT

public:
	Calendar(QWidget *parent=0);
	~Calendar();

public slots:
	void addEvent();
	void deleteEvent();
	void showCalendarGrid(bool show);
	void showWeekNumbers(bool show);
	void showTableGrid(bool show);

protected slots:
	void updateTable(QDate selectedDate);
	void updateCalendar(int year=-1,int month=-1);
	void setSelectedDate(int year, int month);

private:
	QTableWidget *tableWidget;
	QCalendarWidget *calendarWidget;
	QLabel *date;
	QVector<Events> widgets;
	QTextEdit *reminder;
	QTextCharFormat bold;
	QTextCharFormat weekendFormat;
	QTextCharFormat weekdayFormat;

protected:
	int eventCount(QDate date);
	void saveToDisk();
	void saveChangesMade();
	void connectSignalsSlots();
	void forNoneTable(int index);
	void forDailyTable(int index);
	void forWeeklyTable(int index);
	void forMonthlyTable(int index);
	void forYearlyTable(int index);
	void post(int index);
};

#endif //CALENDAR_H
